package com.lw.extraceim.ui.activity.user;

import androidx.appcompat.app.AppCompatActivity;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.InputType;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;

import com.lw.extraceim.R;
import com.lw.extraceim.ui.activity.base.BaseActivity;

public class ChangePassActivity extends BaseActivity {
    private EditText mEditTextPass,mEditTextConfirm;
    private Button mbtnSave;
    private CheckBox mCheckBoxSee1,mCheckBoxSee2;
    private ImageButton mImageButtonBack;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public void initView() {
        setContentView(R.layout.activity_change_pass);
        mEditTextPass=findViewById(R.id.et_user_pass);
        mEditTextConfirm=findViewById(R.id.et_confirm);
        mbtnSave=findViewById(R.id.btn_save_change_password);
        mCheckBoxSee1=findViewById(R.id.cb_see_pass01);
        mCheckBoxSee2=findViewById(R.id.cb_see_pass02);
        mImageButtonBack=findViewById(R.id.btn_back);
    }

    @Override
    public void initData() {

    }

    @Override
    public void refreshUI() {

    }

    @Override
    public void initEvent() {
        mCheckBoxSee1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                {
                    mEditTextPass.setInputType(InputType.TYPE_CLASS_TEXT);
                }
                else
                {
                    mEditTextPass.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            }
        });
        mCheckBoxSee2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked)
                {
                    mEditTextConfirm.setInputType(InputType.TYPE_CLASS_TEXT);
                }
                else
                {
                    mEditTextConfirm.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            }
        });
        mbtnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showDialog();
            }
        });
        mImageButtonBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void showDialog() {
        AlertDialog.Builder builder=new AlertDialog.Builder(this);
        builder.setTitle("提示").setMessage("确定修改吗？").setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                //比对两次输入的密码
                boolean isEqual=mEditTextPass.getText().toString().equals(mEditTextConfirm.getText().toString());
                if(isEqual)
                {
                    //做保存操作
                }
                else
                {
                    Toast.makeText(ChangePassActivity.this,"两次输入密码不相符",Toast.LENGTH_SHORT).show();
                    mEditTextConfirm.setText("");
                    mEditTextPass.setText("");
                    dialog.dismiss();
                }

            }
        }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        }).show();
    }

    @Override
    public void onBackPressed() {
        finish();
    }
}
